<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
import type { DoctorList } from '@/types/consult'
import { getDoctorPage } from '@/services/consult'
import { ref, onMounted } from 'vue'
// import { useWindowWidth } from '@/composable'
// const w = window.innerWidth // 执行一次
// const { w } = useWindowWidth() // 自定义组合式api

const { width } = useWindowSize()

const list = ref<DoctorList>()
const loadData = async () => {
  const res = await getDoctorPage({ current: 1, pageSize: 5 })
  list.value = res.data.rows
}
onMounted(() => loadData())
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe
        :width="(150 / 375) * width"
        :showIndicators="false"
        :loop="false"
      >
        <!-- 
          375屏幕下   swipe-item滑块宽度150
          x屏幕下     swipe-item滑块宽度?

          150/375 = 滑块宽度/屏幕宽度  => 滑块宽度 = 150/375 * 屏幕宽度(window.innerWidth)
         -->
        <van-swipe-item v-for="item in list" :key="item.id">
          <!-- 默认一个屏幕宽度下只展示一个swipe-item -->
          <!-- {{ item }} -->
          <!-- 我们希望DoctorCard不是沾满一个屏幕 而是基于自己宽度进行排列 -->
          <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
